package com.bobi.ecofavor.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bobi.ecofavor.common.utils.JsonResponse;
import com.bobi.ecofavor.service.GoodsService;
import com.bobi.ecofavor.model.domain.Goods;

import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author wenyuan
 * @since 2023-10-21
 * @version v1.0
 */
@Controller
@ResponseBody
@RequestMapping("/api/goods")
public class GoodsController {

//    private final Logger logger = LoggerFactory.getLogger( GoodsController.class );

    @Autowired
    private GoodsService goodsService;

    //根据store的id 查询goods中的部分数据
    @RequestMapping("/getGoodsByStoreId")
    private JsonResponse getGoodsByStoreId(Integer storeId){
        List<Goods> goods = goodsService.getGoodsByStoreId(storeId);
        return JsonResponse.success(goods);
    }

    //根据goods中的id查询goods相应数据和store的部分数据
    @RequestMapping("/getByGoodsId")
    private JsonResponse getByGoodsId(Integer id){
        Goods goods = goodsService.getGAndSByGoodsId(id);
        return JsonResponse.success(goods);
    }

    //根据goods中的id查询goods表中的价格
    @RequestMapping("/getPriceByGoodsId")
    private JsonResponse getPriceByGoodsId(Integer storeId){
        Double price1 = goodsService.getPriceByGoodsId(storeId);
        return JsonResponse.success(price1);
    }
}

